<template>
  <div class="home">
    <!-- 侧边菜单栏 -->

    <el-container>
      <el-aside width="200">
        <div class="manger">LOGO</div>
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          :router="true"
          :collapse="isCollapse"
        >
          <subMenu :sideMenu="sideMenu"></subMenu>
        </el-menu>
      </el-aside>
      <el-container>
        <!-- header区域 -->
        <el-header>
          <el-row type="flex" class="row-bg" justify="space-between">
            <el-col :span="6">
              <div class="grid-content tb-sq">
                <i class="iconfont icon-sq" @click="isCollapse=!isCollapse"></i>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="grid-content title">大学生自主创业管理系统</div>
            </el-col>
            <el-col :span="6">
              <div class="grid-content">
                <el-avatar
                  shape="circle"
                  :size="35"
                  fit="fit"
                  src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1176592211,2114241405&fm=26&gp=0.jpg"
                ></el-avatar>

                <span class="spa">欢迎:</span>
                <a class="nk" @click="$router.push('/Mine')">{{$store.state.userInfo.nickname}}</a>
                <span class="spa1" @click="quit">退出</span>
              </div>
            </el-col>
          </el-row>
        </el-header>
        <!-- main区域 -->
        <el-main>
          <!-- 面包屑 -->
          <el-breadcrumb separator="/">
            <el-breadcrumb-item v-for="item in crumb"
                                :key="item.name"
                                :to="{ path:item.path || '/Welcome'}">
                            <a>{{item.meta.name || "首页"}}</a>
            </el-breadcrumb-item>
            
          </el-breadcrumb>
          <hr />
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import subMenu from "../../components/subMenu";
import { mapState } from "vuex";
import { login } from "@/api";

export default {
  data() {
    return {
      isCollapse: false, //菜单控制menu是否收起
    };
  },
  components: {
    subMenu,
  },
  computed: {
    ...mapState(["sideMenu","crumb"]),
  },
  methods: {
    quit() {
      //清空localStorage中的token 和 nickname
      localStorage.removeItem("user-token");
      localStorage.removeItem("user-userInfo");
      localStorage.removeItem("user-permission");
      //清空vuex中sideMenu中的数据
      this.$store.commit("CLEAR_SIDEMENU");
      //跳转到登录页
      this.$router.push("/login");
      //刷新页面
      window.location.reload();
    },
  },
  mounted() {
    // login().then(res => {
    //   console.log(res);
    //   console.log(res.data.userInfo.nickname);
    //   this.nickname = res.data.userInfo.nickname
    // })
    // console.log(this.$store);
  },
};
</script>
<style scoped>
/*侧边栏样式*/
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.manger {
  background-color: rgb(5, 100, 171);
  border-right: 1px solid #ccc;
  color: #fff;
  font-weight: bold;
  font-size: 20px;
}
.el-aside {
  background-color: rgb(5, 100, 171);
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(6) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(6) .el-aside {
  line-height: 320px;
}

/* layout 顶栏样式 */

.el-header {
  background-color: rgb(5, 100, 171);

  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-avatar--circle,
.spa {
  vertical-align: middle; /*设置元素的垂直对齐方式*/
  margin-right: 5px;
  color: #fff;
}
.nk {
  font-size: 20px;
  color: #fff;
  margin-right: 10px;
  cursor: pointer;
}

.title {
  color: #fff;
  font-size: 25px;
  text-align: left;
}

/*退出样式*/
.spa1 {
  vertical-align: middle;
  color: red;
  font-weight: bold;
  cursor: pointer;
  margin-left: 20px;
}
.grid-content {
  border-radius: 4px;
  height: 60px;
}
.row-bg {
  background-color: -webkit-linear-gradient(
    left,
    rgba(128, 172, 204),
    rgba(5, 100, 171)
  );
}

.grid-content {
  height: 60px;
}

.icon-sq {
  color: #fff;
  font-size: 25px;
  cursor: pointer;
}
.tb-sq {
  text-align: left;
}
</style>